<?php

/**
 * @author thihien
 * @copyright 2011
 */

require_once('includes/general.php');
if(!tep_db_checkDb()) die('khong ket noi dc csdl');
$sql='SELECT count(id) as count FROM `tbl_danh_muc_san_pham` ';
$kq=tep_db_query($sql);
$item1=tep_db_fetch_array($kq);
//bat dau viet phan trang
$display=5;// so san pham xuat hien tren mot trang
$record=$item1['count'];//tong so san pham
if($record>$display){
    $page=ceil($record/$display);
}
else{
    $page=1;
}
$start=isset($_GET['start']) && (int)$_GET['start']?$_GET['start']:0;
$sql4='select * from tbl_danh_muc_san_pham limit '.$start.', '.$display.'';
$kq4=tep_db_query($sql4);
$content='';
if($_SESSION['nn']=='vn'){
                    
                    $content.='<div id="center">
                            
                        <div id="show_sp_theo_dm">';
                            
                                /**
 * $sql6='select * from tbl_danh_muc_san_pham';
 *                                 $kq6=tep_db_query($sql6);
 */
                                while($item=tep_db_fetch_array($kq4)){ 
                                $content.='<div class="sp1">
                                  <div class="tieude_dm"><h3>'.$item['ten_danh_muc_san_pham_vn'].'</h3></div>  
                                  <div class="show_sp">';
                            
                                    $sql7='select * from tbl_san_pham where ma_danh_muc_san_pham='.$item['id'].' limit 8';
                                    $kq7=tep_db_query($sql7);
                                    
                                    while($item1=tep_db_fetch_array($kq7)){ 
                                        $content.='<div class="show_sanpham">
                                            <div class="hinhanh_sp" style="margin-bottom: 10px;"><a href="?page=sanpham&masp='.$item1['id'].'&madanhmucsp='.$item1['ma_danh_muc_san_pham'].'&mode=detail"><img width="110" height="110" src="admincp/upload/'.$item1['hinh_anh'].'"/></a></div>
                                            <div class="tieude_sp">
                                                <div style="margin-top: 5px;" class="ten_sp_center"><a href="#"> '.$item1['ten_san_pham_vn'].' </a></div>
                                                </div>
                                          
                                            <div class="clear"></div>
    
                                        </div>';
    
                                     
                                    } 
                                  $content.=' </div> 
                                </div>';   
                                
                                }
                                
                            $content.='
        <ul class="phantrang">';
         $content.='Trang:';
            if($page>1){
                $next=$start+$display;
                $prev=$start-$display;
                $current=($start/$display)+1;
                //hien thi phan trang prev
               
                if($current!=1){
                   $content.='<li><a href="?page=center_content&start='.$prev.'">Previous</a></li>'; 
                }
                 //hien thi trang
                 for($i=1;$i<=$page;$i++){
                   if($current!=$i){
                        $content.='<li><a href="?page=center_content&start='.$display*($i-1).'">'.$i.'</a></li>'; 
                    } 
                    else
                    {
                       $content.='<li class="current"><a href="?page=center_content&start='.$display*($i-1).'">'.$i.'</a></li>'; 
                    }
                     
                 }
                //hien thi next
                if($current!=$page){
                    $content.='<li><a href="?page=center_content&start='.$next.'">Next</a></li>';  
                }
            }
            else{
                $content.='<li class="current" ><a href="?page=center_content&start=0">'.$page.'</a></li>';  
            }
       $content.=' </ul';
                        $content.='</div>
                   
                   <!--
 <div class="clear"></div>
-->

                </div>';
                       
                    }
                
  echo $content;               
?>